package com.mysoft.gfyx.common.util;

import java.util.ArrayList;

public class MyStringUtil {

    public static String ReplaceSpecifiedStr(int start, int end, String sourceStr, String SpecifiedStr, int len) {
        int strLen = sourceStr.length();
        if (strLen > 0 && (strLen > (end - start))) {
            StringBuilder res = new StringBuilder();
            res.append(sourceStr.substring(start, end));
            for (int i = 0; i < len; i++) {
                res.append(SpecifiedStr);
            }
            return res.toString();
        } else {
            return "";
        }
    }

    public static String GetStrNum(String strValue, Integer maxLimit) {
        if (strValue.length() <= 14) {
            return strValue;
        } else {
            String newStr = strValue.substring(0, 14) + "...";
            return newStr;
        }
    }

    public static Object TranArrayToStr(String operator, Object val) {
        if ("in".equals(operator) && val instanceof ArrayList<?>) {
            // 处理成 , 逗号隔开
            ArrayList<?> newValue = (ArrayList<?>) val;
            if (newValue.isEmpty()) {
                return "";
            } else {
                StringBuilder sb = new StringBuilder();
                for (Object element : newValue) {
                    sb.append(element).append(",");
                }
                return sb.deleteCharAt(sb.length() - 1).toString();
            }
        } else {
            return val;
        }
    }

    public static String spiltString(String data) {
        String[] arr;
        if (data.contains(";")) {
            arr = data.split(";");
        } else if (data.contains("；")) {
            arr = data.split("；");
        } else if (data.contains(",")) {
            arr = data.split(",");
        } else if (data.contains("、")) {
            arr = data.split("、");
        } else if (data.contains("/")) {
            arr = data.split("/");
        } else {
            arr = data.split("%");
        }
        return arr[0];
    }
}
